#include "sdlengine.hpp"

#include "benchmark/benchmark.hpp"

using namespace sdl_engine;

class Application: public App {
public:
    void Init() override {
        engine.SetFPS(engine.NoFPSLimit);
        engine.ShowFPS();
        texture_ = new Texture("sandbox/asset/cube_man.png");
        font_ = engine.GetFontStock().Create("tests/assets/SimHei.ttf", 20);
    }

    void Shutdown() override {
        delete texture_;
    }

    void Update(int milliseconds) override {}

    void Render(Renderer& renderer) override {
        renderer.RenderCopy(texture_, point(100, 100), size(400, 400));

        renderer.SetDrawColor(color(255, 0, 0));
        renderer.RenderFillRect(rect(100, 100, 50, 50));

        SubTexture subTexture(texture_,
                              rect(64, 64, 64, 64));
        renderer.RenderCopy(&subTexture,
                            point(50, 50),
                            size(200, 200),
                            color(255, 255, 255, 100));

        engine.GetInnerBmpFont().Render("this is inner bmp font",
                                        16,
                                        point(100, 100),
                                        color(0, 255, 255));
        renderer.RenderUTF8(*font_,
                            "SandBox test OK",
                            point(200, 200),
                            color(255, 255, 255));
    }

private:
    Texture* texture_ = nullptr;
    Font* font_ = nullptr;
};

int main(int argc, char** argv) {
    Window::CreateInfo windowInfo;
    windowInfo.SetTitle("SandBox")
              .SetSize(size(720, 480))
              .EnableResize();

    Renderer::CreateInfo rendererInfo;

    Application app;

    {
        component::benchmark::Benchmark benchmark("engine init");
        engine.Init(argc, argv, windowInfo, rendererInfo, true);
    }

    engine.SetApp(&app);

    RUN_ENGINE();

    engine.Shutdown();
    return 0;
}
